package org.discala.samples.simple

import scala.util.Random

/**
 * @author Chris Turner
 */
trait InMemoryQuoteRepositoryComponent {

  val repository: () => QuoteRepository

  class InMemoryQuoteRepository extends QuoteRepository {

    private val quotes = Array(
      "If you only have a nail then everything appears to be a hammer",
      "Doh!",
      "Scala is a great programming language",
      "We love dependency injection",
      "I'll be back",
      "Life is like a box of chocolates...")

    private val random = new Random()

    def quote() = {
      random.synchronized {
        quotes(random.nextInt(quotes.length))
      }
    }
  }
}
